package com.nekonomics
package api.dto.response

import domain.detail.SkuSpecDetail
import domain.entity.Sku
import types.Money

import zio.json.JsonEncoder

case class SkuDetailDto(
  id: Long,
  spuId: Long,
  price: Money,
  stock: Int,
  imageUrl: Option[String],
  specValueIds: List[Long]
  //  createdAt: OffsetDateTime,
  //  updatedAt: OffsetDateTime
) derives JsonEncoder


object SkuDetailDto {
  def of(sku: Sku, specs: List[SkuSpecDetail]): SkuDetailDto = {
    SkuDetailDto(
      id = sku.id,
      spuId = sku.spuId,
      price = sku.price,
      stock = sku.stock,
      imageUrl = sku.imageUrl,
      specValueIds = specs.map(_.specValueId)
    )
  }
}